@using Elsa.Api.Client.Resources.WorkflowDefinitions.Models
@inherits StudioComponentBase

<div class="pa-4">
    <MudTable
        @ref="Table"
        ServerData="LoadVersionsAsync"
        T="WorkflowDefinitionSummary"
        Hover="true"
        Dense="true"
        Bordered="false"
        Striped="false"
        Elevation="0"
        Outlined="true"
        FixedHeader="true">
        <HeaderContent>
            <MudTh>Used</MudTh>
            <MudTh>Version</MudTh>
            <MudTh>Created</MudTh>
            <MudTh></MudTh>
        </HeaderContent>
        <RowTemplate>
            <MudTd>
                @if (context.Version == CurrentVersionUsed)
                {
                    <MudIcon Icon="@Icons.Material.Filled.Check" Color="Color.Success"/>
                }
            </MudTd>
            <MudTd>@context.Version</MudTd>
            <MudTd>@context.CreatedAt.ToString("g")</MudTd>
            <MudTd style="text-align: right;">
                <MudMenu Icon="@Icons.Material.Filled.MoreVert" Disabled="IsReadOnly || !_versionsUsableAsActivity.Contains(context.Version)" Title="@(!_versionsUsableAsActivity.Contains(context.Version) ? "Not usable as activity." : "")">
                    <MudMenuItem OnClick="@(() => OnUseVersionClicked(context))">Use this version</MudMenuItem>
                </MudMenu>
            </MudTd>
        </RowTemplate>
        <PagerContent>
            <MudTablePager/>
        </PagerContent>
    </MudTable>
</div>